"""
配置文件
"""

# 默认密码序列
DEFAULT_PASSWORD_SEQUENCE = ["circle", "triangle", "rectangle"]

# 图形识别参数
SHAPE_DETECTION_CONFIG = {
    # 最小轮廓面积，过滤小的噪声（从1000调整为500以适应小图形）
    "min_contour_area": 500,
    
    # 轮廓近似的epsilon因子，控制多边形近似的精度
    "approx_epsilon_factor": 0.02,
    
    # 高斯模糊核大小
    "blur_kernel_size": 5,
    
    # 形态学操作核大小
    "morph_kernel_size": 3,
    
    # 自适应阈值参数
    "adaptive_threshold_block_size": 11,
    "adaptive_threshold_c": 2,
    
    # 置信度阈值
    "min_confidence_threshold": 0.5,
    
    # 图形分类参数
    "circle_circularity_threshold": 0.7,
    "square_aspect_ratio_tolerance": 0.1,  # 从0.05改为0.1，放宽正方形识别条件
    "rectangle_aspect_ratio_min": 1.2,
    
    # 角度容差（度）
    "angle_tolerance": 10,
}

# 新增：检测模式配置
DETECTION_MODE_CONFIG = {
    # 检测模式：'traditional' 或 'yolo'
    "default_mode": "traditional",
    
    # YOLO模型路径
    "yolo_model_path": "models/yolov5s.pt",
    
    # 调试模式开关
    "debug_mode": False,
}

# Gradio界面配置
GRADIO_CONFIG = {
    "server_port": 7868,
    "share": False,
    "debug": True,
    "server_name": "0.0.0.0",  # 允许外部访问
    "inbrowser": True,  # 自动打开浏览器
    "favicon_path": None,
    "ssl_keyfile": None,
    "ssl_certfile": None,
    "ssl_keyfile_password": None,
    "quiet": False,
}

# 密码锁配置
PASSWORD_LOCK_CONFIG = {
    # 最大尝试次数
    "max_attempts": 3,
    
    # 锁定超时时间（秒）
    "lock_timeout": 30,
    
    # 检查间隔时间（秒），避免频繁检查
    "check_interval": 1.0,
    
    # 图形识别的最低置信度要求
    "min_confidence_for_unlock": 0.7,
    
    # 支持的密码图形类型
    "supported_shapes": ["circle", "triangle", "square", "rectangle"],
    
    # 自动重置时间（分钟），0表示不自动重置
    "auto_reset_minutes": 0,
}

# 图像处理配置
IMAGE_PROCESSING_CONFIG = {
    # 最大图像尺寸
    "max_image_size": 800,
    
    # 支持的图像格式
    "supported_formats": ['.jpg', '.jpeg', '.png', '.bmp', '.tiff', '.tif'],
    
    # 图像增强参数
    "contrast_alpha": 1.2,
    "contrast_beta": 10,
    
    # 噪声去除参数
    "noise_removal_kernel_size": 3,
    "noise_removal_iterations": 1,
}

# 演示配置
DEMO_CONFIG = {
    # 演示图像尺寸
    "demo_image_size": (300, 300),
    
    # 演示图形颜色
    "demo_colors": {
        "triangle": "lightblue",
        "square": "lightgreen", 
        "rectangle": "lightcoral",
        "circle": "lightyellow",
        "background": "white"
    },
    
    # 演示图形大小
    "demo_shape_size": 80,
}

# 摄像头配置
CAMERA_CONFIG = {
    # 摄像头索引
    "camera_index": 0,
    
    # 拍照图像尺寸
    "capture_size": (640, 480),
    
    # 是否启用摄像头功能
    "enable_camera": True,
}

# 日志配置
LOGGING_CONFIG = {
    "level": "INFO",
    "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    "log_to_file": False,
    "log_file_path": "logs/shapes_recognizer.log",
}

# 性能配置
PERFORMANCE_CONFIG = {
    # 摄像头帧率
    "webcam_fps": 15,
    
    # 实时处理的图像缩放比例
    "realtime_scale_factor": 0.5,
    
    # 批处理大小
    "batch_size": 1,
    
    # 缓存配置
    "enable_cache": True,
    "cache_size": 100,
}

# UI配置
UI_CONFIG = {
    # 主题
    "theme": "soft",  # 可选: default, soft, monochrome
    
    # 界面标题
    "title": "图形识别系统",
    
    # 界面描述
    "description": "基于OpenCV的实时图形识别，支持三角形、正方形、长方形、圆形识别",
    
    # Tab标签
    "tab_labels": {
        "image_recognition": "📷 图像识别",
        "realtime_recognition": "🎥 实时识别", 
        "password_lock": "🔐 图形密码锁"
    },
    
    # 按钮标签
    "button_labels": {
        "detect": "识别图形",
        "check_password": "检查密码",
        "reset": "重置",
        "upload": "上传图像"
    },
    
    # 组件标签
    "component_labels": {
        "image_input": "上传图像",
        "image_output": "识别结果",
        "result_text": "识别详情",
        "webcam_input": "摄像头",
        "webcam_output": "实时识别结果",
        "status_text": "识别状态",
        "lock_input": "密码输入",
        "lock_output": "输入图形",
        "lock_status": "解锁进度",
        "lock_message": "状态消息"
    }
}

# 错误消息配置
ERROR_MESSAGES = {
    "no_image": "请上传图像",
    "webcam_not_started": "摄像头未启动",
    "no_shapes_detected": "未识别到任何图形",
    "invalid_image_format": "不支持的图像格式",
    "image_too_large": "图像尺寸过大",
    "processing_error": "图像处理时出错",
    "lock_timeout": "密码锁已被锁定，请稍后再试",
    "invalid_password_sequence": "无效的密码序列",
    "system_error": "系统错误，请重试"
}

# 成功消息配置
SUCCESS_MESSAGES = {
    "shapes_detected": "成功识别图形",
    "password_correct": "密码正确",
    "unlock_success": "解锁成功",
    "system_reset": "系统已重置",
    "settings_saved": "设置已保存"
}

# 开发配置
DEVELOPMENT_CONFIG = {
    # 是否启用调试模式
    "debug_mode": True,
    
    # 是否显示详细错误信息
    "show_detailed_errors": True,
    
    # 是否启用性能监控
    "enable_performance_monitoring": False,
    
    # 是否自动生成演示图像
    "auto_generate_demo_images": True,
    
    # 测试模式
    "test_mode": False,
}